
    $(function () {
        if ($("div.protected-form").length) {

            $("#submit-button").attr("disabled", "disabled");

            $("#submit-button").click(function () {
                    $("#submit-button").attr("disabled", "disabled");
                    $("form").submit();
                }
            );

            $("form").change(function () {
                $("#submit-button").removeAttr('disabled');
            });

            $("form input").keypress(function () {
                $("#submit-button").removeAttr('disabled');
            });

        }
    });


    $(window).bind('beforeunload', function (e) {
        if ($("div.protected-form").length) {
            if ($("#submit-button").is(':enabled')) {
                var message = "There are some unsaved data. All changes will be lost.";
                e.returnValue = message;
                return message;
            }
        }
    });
